package tianxiao.web.test;

import cn.hutool.core.io.resource.ResourceUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.junit.Test;
import org.yaml.snakeyaml.Yaml;
import yun.web.activerecord.dialect.ARP;

public class App {
    public static void main(String[] args) {
        yun.web.undertow.UndertowServer.create()
                .addHotSwapClassPrefix("tianxiao.web.test.")
                .setPort(3123)
                .start();
    }

    @Test
    public void generateModel() throws Exception {
        Yaml yaml = new Yaml();
        Object datasource = yaml.load(ResourceUtil.readUtf8Str("datasource.yml"));
        JSONObject jb = JSON.parseObject(JSON.toJSONString(datasource));

        JSONArray dbConfigList = jb.getJSONArray("datasource");

        ARP.generate(dbConfigList);
    }

    /*    @Test
    public void buildCmd() {

        //String f = SystemUtil.getOsInfo().isWindows() ? ";" : ":";
        String f = ":";

        String mainClass = "tianxiao.web.test.App";

        ArrayList<String> list = new ArrayList<>();

        String prefix = "./lib/";

        for (File file : new File(new File("").getAbsolutePath() + "/target/classes/lib").listFiles()) {
            String name = file.getName();
            if (file.isFile() && name.endsWith(".jar")) {
                list.add(prefix + name);
            }
        }
        String cmd = "java -classpath \"" + CollUtil.join(list, f) + f + "\" " + mainClass;
        System.out.println(cmd);
    }*/
}
